package kr.hkit.androidcomplete03.ETC;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class VoteTest extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.votemain);
		
		final int[] voteCount = new int[9];
		for(int i= 0; i < 9; i++){
			voteCount[i] = 0;
		}
		
		ImageView[] image = new ImageView[9];
		Integer[] imageId = {R.id.imageView1, R.id.imageView2, R.id.imageView3, R.id.imageView4, R.id.imageView5, R.id.imageView6, R.id.imageView7, R.id.imageView8, R.id.imageView9};
		final String[] imgName = {"독서하는 소녀", "꽃장식 모자 소녀", "부채를 든 소녀", "이레느깡 단 베르양", "잠자는 소녀", "테라스의 두 자녀", "피아노 레슨", "피아노 앞의 소녀들", "해변에서"};
		
		for(int i = 0; i < imageId.length; i++){
			final int index;
			index = i;
			image[index] = (ImageView) findViewById(imageId[index]);
			image[index].setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					voteCount[index]++;
					Toast.makeText(getApplicationContext(), imgName[index] + ": 총 " + voteCount[index] + "표", 0).show();
				}
				
			});
		}
		
		Button btnFinish = (Button) findViewById(R.id.voteresult);
		btnFinish.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), ResultActivity.class);
				intent.putExtra("VoteCount", voteCount);
				intent.putExtra("ImageName", imgName);
				startActivity(intent);
			}
			
		});
	
	}
}
